
#include "C:\SAFIRE\Y\Y_BIFn\Y_BIFn.y.h"

#include "C:\SAFIRE\Y\PH_SL.y.h"

#include "C:\SAFIRE\Y\Mgt_SL.y.h"

#include "C:\SAFIRE\Y\ConfigUdp_TP.y.h"

#include "C:\SAFIRE\Users\SIP_USER\ws\SIP\source\Common_LIB\Scenario_HTML_Gen.y.h"

#include "C:\SAFIRE\USERS\SIP_USER\ws\SIP\source\SIP_LIB\SIP_LIB.y.h"


typedef SIP_ST_QC_OE_V [SIP_Signals_T SIP_G, PH_SL UDP_Data_G, Mgt_SL UDP_Mgt_G]
{
            
    TIMER SIGNAL        TSupervisor();
    TIMER SIGNAL        TAct_Rq();
    TIMER SIGNAL        TResponse();
    TIMER SIGNAL        TStart();
	TIMER SIGNAL		TWaitAck();
	TIMER SIGNAL		TWaitBye();
	TIMER SIGNAL		TPostamble();
	       
    Request_T           Request_RX_1;
    
    Response_T          Response_T_TX_1;
    Response_T          Response_T_TX_2;
    Response_T          Response_T_RX_1;
    Response_T          Response_T_RX_2;
    
    Request_Line_T      Request_Line;
    Message_Headers_T   Message_Headers;
    Message_Body_T      Message_Body;
    Status_Line_T       Status_Line;
    
    PH_SL               PH_SL_S;
    SIP_Signals_T       SIP_Signal;    
    Config_UDP_T        ConfigUDP;
    
    STRING              CRLF;
        
    STRING              ScenarioName;
    STRING              ScenarioDecription;
    STRING              HTML_Title;
    STRING              HTMLFilePath;
    STRING              Mode;
    STRING				Supported_Tester;
	STRING				Supported_Tester;
	
	NUMBER              HTML_File;
	NUMBER				Retry_Cancel;
	
	SIP_Addr_Spec_T		SUT_Addr;
	SIP_Addr_Spec_T		Tester_Addr;
	
  
    SUT_Addr.SIP_URI.UserInfo.User = "228";
	SUT_Addr.SIP_URI.UserInfo.Password = NULL;	
	SUT_Addr.SIP_URI.HostPort.Host = "10.0.1.85";
	SUT_Addr.SIP_URI.HostPort.Host = "192.168.0.3";
	SUT_Addr.SIP_URI.HostPort.Port = 5060;	
	SUT_Addr.SIP_URI.URI_Parameters = NULL;
	SUT_Addr.SIP_URI.URI_Headers = NULL;
	
    Tester_Addr.SIP_URI.UserInfo.User = "1000";
	Tester_Addr.SIP_URI.UserInfo.Password = NULL;	
	Tester_Addr.SIP_URI.HostPort.Host = "10.0.1.158";
	Tester_Addr.SIP_URI.HostPort.Host = "192.168.0.4";
	Tester_Addr.SIP_URI.HostPort.Port = 5060;	
	Tester_Addr.SIP_URI.URI_Parameters = NULL;
	Tester_Addr.SIP_URI.URI_Headers = NULL;
	
	Supported_Tester		= "replaces,norefersub,timer";
	SIP_Version_Tester		= "SIP/2.0";
	Tag_Tester 				= "tag=a3bhg";
		
    
    Mode= "ab";
    HTMLFilePath= "C:\\SAFIRE\\Temp\\SIP_ST_QC_OE_V.html";    
    
    HTML_File= OpenFile( HTMLFilePath,
                         Mode);
    IF (HTML_File EQ 0)
    {
        Print( "SIP_ST_QC_OE - Can't open C:\\SAFIRE\\Temp\\");
        Print( "SIP_ST_QC_OE - Please create this directory C:\\SAFIRE\\Temp\\");
        STOP;
    }
                             
    HTML_Title = "SIP_ST_QC_OE_V";
    ScenarioName = "SIP_ST_QC_OE_V";
    ScenarioDecription = "basic call - passive part";
    Scenario_Gen_HTML_Header( HTML_File,
                              HTML_Title,
                              ScenarioName,
                              ScenarioDecription);

    START TStart FOR 1000;
    Print("\n\nScenario_1 : ---  started");
    
    ? .TStart()
    {
         Print("\n\nScenario_1 : ---  started");
         :: Preamble;
    }        
     
    
    STATE Preamble
    {        
        Print("SIP_ST_QC_OE - Start UDP config");
        ConfigUDP.Src.IpAddress=        Tester_Addr.SIP_URI.HostPort.Host;
        ConfigUDP.Src.Port=             Tester_Addr.SIP_URI.HostPort.Port;
        
        ConfigUDP.Dst.IpAddress=        SUT_Addr.SIP_URI.HostPort.Host;
        ConfigUDP.Dst.Port=             SUT_Addr.SIP_URI.HostPort.Port;
        
        ConfigUDP.MaxPacketSize=        1024;
        Print("SIP_ST_QC_OE - End UDP config");

        Print("SIP_ST_QC_OE - Configuring UDP");
        UDP_Mgt_G ! Mgt_SL.Configure( ConfigUDP);
        
        Print("SIP_ST_QC_OE - Activating UDP");
        UDP_Data_G ! PH_SL.PH_Act_Rq();
        START TAct_Rq FOR 10000;
    
        UDP_Data_G ? PH_SL.PH_Act_Ind() : PH_SL_S 
        {
            Print( "SIP_ST_QC_OE - UPD Activated");
            START TSupervisor FOR 10000;
            
            Scenario_Gen_HTML_Verdict( HTML_File,
                                       0, 
                                       "PASS",
                                       "UDP activated");
            :: Wait_Options;
        }
        
        UDP_Data_G ? PH_SL.PH_Deact_Ind() : PH_SL_S 
        {
            Print( "SIP_ST_QC_OE - UPD Act_Rq not successfull  ... PH_Deact_Ind received!");
            
            Scenario_Gen_HTML_Verdict( HTML_File,
                                       1, 
                                       "FAIL",
                                       "UPD Act_Rq not successfull  ... PH_Deact_Ind received!");            
            STOP;
        }
        
        ? .TAct_Rq()
        {
            Print( "SIP_ST_QC_OE - UPD Act_Req not received  ... Timeout!");
            Scenario_Gen_HTML_Verdict( HTML_File,
                                       1, 
                                       "FAIL",
                                       "UPD Act_Req not received  ... timeout!");
                                       
            STOP;
        }                
    }             
     
    STATE Wait_Options
    {            
		Print("SIP_ST_QC_OE - Starting");
		
		START TStart FOR 10000;
		
		? .TStart()
		{
            Print( "SIP_ST_QC_OE - Options not received... Timeout!");
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "Options not received... timeout!"); 
            STOP;
        }
		
        SIP_G ? SIP_Signals_T.SIP_Options (?) : SIP_Signal
		{
			Print("SIP_ST_QC_OE - SIP_Options message received");
			Print(SIP_Options);
			
			
			Request_RX_1 = SIP_Signal.SIP_Options.Request;
            Print(Request_RX_1);
			
            Scenario_Gen_HTML_Verdict( HTML_File, 1, "PASS", "Tester received OPTIONS from SUT");
			
			Message_Headers = NULL;
			Message_Headers = Request_RX_1.Message_Headers;
			
			
			IF ((Message_Headers.To NEQ NULL) AND
				(Message_Headers.From NEQ NULL) AND
				(Message_Headers.CSeq NEQ NULL) AND
				(Message_Headers.Call_Id NEQ NULL) AND
				(Message_Headers.Max_Forwards NEQ NULL) AND
				(Message_Headers.Via NEQ NULL))
			{
				Print("SIP_ST_QC_OE - VERDICT: PASS! - Parameters headers are there");
				Scenario_Gen_HTML_Verdict( HTML_File, 1, "PASS", "Parameters headers are there");
			}
			ELSE
			{
				Print("SIP_ST_QC_OE - VERDICT: FAIL! - Parameters headers missing");
				Scenario_Gen_HTML_Verdict( HTML_File, 1, "FAIL", "Parameters headers missing");
			}
			START TPostamble FOR 3000;
			:: Postamble;
		}
		

    }
	
		
	STATE Postamble
    {	
        ? .TPostamble()
        {
			Print("SIP_ST_QC_OE - ... ending the test scenario");
			UDP_Data_G ! PH_SL.PH_Deact_Rq();
	        Scenario_Gen_HTML_Footer( HTML_File);
	        CloseFile( HTML_File);
        STOP;
		}
    }
};